<?php
$oForm = new cForm ('login', 'login');
$oForm -> addInput ('Gebruikersnaam', 'text', NULL, true)
	   -> addInput ('Wachtwoord', 'password', NULL, true)
	   -> addButton ('Login');

if ($oForm -> isPosted ())
{
	$sUsername	= (isset ($_POST['Gebruikersnaam'])) ? $_POST['Gebruikersnaam'] : '';
	$sPassword	= (isset ($_POST['Wachtwoord'])) ? cFunctions::hashPassword($_POST['Wachtwoord']) : '';

	$user = new cModel ('user', 'gebruikersnaam', $_POST ['Gebruikersnaam']);
	if ($sUsername != $user -> gebruikersnaam || $sPassword != $user -> password)
	{
		echo 'Je hebt een verkeerde gebruikersnaam/wachtwoord ingevuld. ' . cFunctions :: goBack ();
	}
	else
	{
		$_SESSION['user_id'] = $user -> user_id;
		$_SESSION['username'] = $user -> gebruikersnaam;
		$_SESSION['fullname'] = $user -> voornaam . ' ' . $user -> achternaam;
		$_SESSION['email'] = $user -> email;
		header ('Refresh: 3; url=javascript:history.go (-2)');
		echo 'Je bent nu ingelogd. ' . cFunctions::goBack();
	}
}
else
{
	if (!isset ($_SESSION ['user_id']))
	{
		echo $oForm -> output ();
	?>
<!--	<form method="POST" action="/9/Login.html">
			<table cellpadding="0" cellspacing="0" border="0" style="table-layout:fixed" width="225">
				<tr>
					<td width="75">Gebr.naam:</td>
					<td width="150" align="center"><input type="text" name="gebruikersnaam" size="15" maxlength="255" /></td>
				</tr>
				<tr>
					<td width="75">Wachtwoord:</td>
					<td width="230" align="center"><input type="password" name="password" size="15" maxlength="25" /></td>
				</tr>
			</table>
			<p><br /></p>
			<input type="submit" value="Login" name="B1" />&nbsp;&nbsp;<input type="reset" value="Invoer wissen" name="B2" />
		</form> -->
	<?php
	}
	else
	{
		echo 'U bent al ingelogd als: '.$_SESSION['username'];
		?>
		<form method="POST" action="/7/Loguit.html">
		<input type="submit" value="Loguit" name="B1">
		</form><?php
	}
}